import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false

// 引入axios插件
import axios from 'axios'
Vue.prototype.$http = axios
axios.defaults.baseURL = 'http://ayong6.free.idcfengye.com';
// axios.defaults.baseURL = 'http://127.0.0.1:7001';

// 按需引入antd
import './plugins/ant-design.js'
import '@/assets/style/pages/comm.css'
import '@/assets/style/pages/index.css'

// 引入markdown解析插件:mavon-mavon-editor
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)

//请求拦截器
axios.interceptors.request.use(function (config) {
  if (localStorage.getItem('token')) {
    let token = localStorage.getItem('token');
    config.headers.common['Authorization'] = 'Bearer ' + token;
  }
  return config;
}, function (error) {
  return Promise.reject(error);
});
// 响应拦截器
axios.interceptors.response.use(response => {
  return Promise.resolve(response);
}, error => {
  switch (error.response.status) {
    case 401:
      localStorage.removeItem('token')
      router.push('/admin');
      break;
    default: break;
  }
  return Promise.reject(error);
})


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
